SOFTWARE NEEDED TO RUN MF IN R

HOW TO RUN MF:

Here are four main functions we provide in this package :

Normalized the raw data: func_normalized()

We first describe the normalized function func_normalized() with default arguments, and the arguments of this function are briefly described below.

func_normalized <- function(data, fun_cols = 1:ncol(data), negative = NULL, by_group = NULL) 
Argument Description
data data can be input as a matrix/data.frame (multiple plots by functions).
fun_cols the order number of the columns which be used as the ecosystem function.
negative name of columns to be normalized negatively.
by_group <name of the column to normalized by group. Default is NULL.

Multi-functionality: MF_single()

One of the main function to measure MF is MF_single(), and the following is default arguments of the function:

MF_single <- function(func_data, species_data = NULL, q = c(0, 1, 2))

The arguments of this function are briefly described below, and will be explained in more details by illustrative examples in later text. This main function computes quantification multi-fuctionality of order q in a single ecosystem when all functions are assumed to be independent and when the correlation is considered.

Argument Description
func_data the ecosystem function data can be input as a vector of functions (for a single assemblage), matrix/data.frame (assemblages by functions). The data input must be normalized between 0 and 1 already and must contain only the ecosystem function columns.. For species_data is not NULL, the rownames of func_data should be names of ‘plotID’.
species_data the species abundance data must include three columns: ‘plotID’, ‘species’ and ‘abundance’. Default is NULL.
q a numerical vector specifying the diversity orders. Default is 0, 1 and 2.

Multi-functionality: MF_multiple()

The other main function to measure MF is MF_multiple(), and the following is default arguments of the function:

MF_multiple <- function(func_data, species_data = NULL, q = c(0, 1, 2), by_group = NULL) 

The arguments of this function are briefly described below, and will be explained in more details by illustrative examples in later text. This main function computes decomposition multi-fuctionality of order q in multiple ecosystems when all functions are assumed to be independent and when the correlation is considered.

Argument Description
func_data the ecosystem function data can be input as a vector of functions (for a single assemblage), matrix/data.frame (assemblages by functions). The data input must be normalized between 0 and 1 already. For by_group = NULL the func_data must contain only the ecosystem function columns. Otherwise, you must add the by_group column in data. For species_data is not NULL, the rownames of func_data should be names of ‘plotID’.
species_data the species abundance data must include three columns: ‘plotID’, ‘species’ and ‘abundance’. Default is NULL.
q a numerical vector specifying the diversity orders. Default is 0, 1 and 2.
by_group name of the column to be paired by group. Default is NULL.

The above two functions returns a data.frame which can be further used to make plots using the function ggMF() to be described below.

Example Data

A forest tree species and ecosystem function data is included in MF package for illustration. In the data, a total of 209 plots were established in mature forests in six countries, representing six major European forest types: boreal forest (Finland); hemi-boreal (Poland); temperate deciduous (Germany); mountainous deciduous (Romania); thermophilous deciduous (Italy); and Mediterranean mixed (Spain). In each country, three to five common tree species were selected for the species pool; species richness in 209 plots consisted of one to five species sampled from the species pool. A total of 26 ecosystem functions or properties were measured in each plot.

For this data, the following commands display how to compute multi-functionality and corresponding decomposition in multiple ecosystems .

Ecosystem functions data

Run the following code to view raw forest data: (Here we only show the first ten rows of the first three ecosystem functions)

data("Europe_Forest_raw")
Europe_Forest_raw
#>       plotid target_species_richness composition earthworm_biomass fine_woody_debris microbial_biomass_mineral
#> FIN01  FIN01                       2   Piab.Pisy             0.000               171                   135.637
#> FIN02  FIN02                       2     Be.Piab             0.465               110                   350.680
#> FIN03  FIN03                       2     Be.Piab             0.626                81                   570.391
#> FIN04  FIN04                       2     Be.Piab             0.000                82                   441.666
#> FIN05  FIN05                       2     Be.Pisy             0.928                38                   516.979
#> FIN06  FIN06                       1        Piab             0.000                75                   611.220
#> FIN07  FIN07                       1          Be            49.672                44                   782.070
#> FIN08  FIN08                       1          Be            28.013                38                   364.591
#> FIN09  FIN09                       1        Pisy             0.204                65                   376.450
#> FIN10  FIN10                       1        Piab             0.000               136                   752.274

Since the data is not normalized, we then use func_normalized() to do standardization. Note that, in this data, the ecosystem functions are column 4 to column 29. And there are two ecosystem functions should be normalized negatively: "soil_cn_ff_10" and "wue". Furthermore, the performance of the ecosystem functions are quite different between six countries, thus, we do normalization and analysis among each countries.

data("Europe_Forest_raw")
norm_Europe_Forest = func_normalized(data = Europe_Forest_raw, 
                                     fun_cols = 4:29, 
                                     negative = c("soil_cn_ff_10","wue"), 
                                     by_group = "Country")
head(cbind(norm_Europe_Forest[1:3], round(norm_Europe_Forest[4:6], 3)), 10)

This normalized data is same as the data Europe_Forest in MF package .

Species abundance data

Run the following code to view complete species abundance data:

data("Europe_Forest_species")
Europe_Forest_species

Here, we only show the first ten rows.

#> # A tibble: 10 × 3
#> # Groups:   plotID [5]
#>    plotID species          abundance
#>    <chr>  <chr>                <dbl>
#>  1 FIN01  Picea.abies          1.84 
#>  2 FIN01  Pinus.sylvestris     0.535
#>  3 FIN02  Betula.pendula       1.18 
#>  4 FIN02  Picea.abies          0.408
#>  5 FIN03  Betula.pendula       1.09 
#>  6 FIN03  Picea.abies          0.215
#>  7 FIN04  Betula.pendula       0.662
#>  8 FIN04  Picea.abies          1.14 
#>  9 FIN05  Betula.pendula       0.423
#> 10 FIN05  Pinus.sylvestris     1.25

Computing Multi-functionality Via Example

If the species_data is not provided

For example, given a normalized data, we run the MF_single() function without setting species_data to compute uncorrelated and correlated multi-functionality. (Here we only show the first six outputs)

data("Europe_Forest")
output1 <- MF_single(func_data = Europe_Forest[,4:29])
output1 %>% mutate(qMF = round(qMF,3)) %>% head(6)

The output contains ID of plot (plotID) which is according to the row names of the input data, Type (uncorrelated or correlated), the diversity order (Order.q) and multi-functionality (qMF).

If there is species_data given to function MF_single

data("Europe_Forest")
data("Europe_Forest_species")
output2 <- MF_single(func_data = Europe_Forest[,4:29],species_data = Europe_Forest_species)
#>   plotID         Type Order.q    qMF Species.diversity
#> 1  FIN01 Uncorrelated   q = 0 10.711             2.000
#> 2  FIN01 Uncorrelated   q = 1 10.026             1.704
#> 3  FIN01 Uncorrelated   q = 2  9.577             1.535
#> 4  FIN01   Correlated   q = 0 10.351             2.000
#> 5  FIN01   Correlated   q = 1  9.704             1.704
#> 6  FIN01   Correlated   q = 2  9.275             1.535

The output has only more column Species.diversity than the previous one.

Computing Decomposition of Multi-functionality In Multiple Ecosystems Via Example

For example, we run the MF_multiple() function with forest data to compute uncorrelated and correlated multi-functionality relationships across spatial scales. (Here we only show the first six outputs)

data("Europe_Forest")
output3 = MF_multiple(func_data = Europe_Forest[,4:30],
                      species_data = Europe_Forest_species,
                      by_group = "Country")
#>             plotID Country Order.q MF_gamma MF_alpha MF_beta
#> 1 FIN01 v.s. FIN02     FIN   q = 0   10.016   10.010   1.001
#> 2 FIN01 v.s. FIN02     FIN   q = 1    9.356    8.713   1.074
#> 3 FIN01 v.s. FIN02     FIN   q = 2    8.838    7.995   1.105
#> 4 FIN01 v.s. FIN03     FIN   q = 0    9.699    9.466   1.025
#> 5 FIN01 v.s. FIN03     FIN   q = 1    9.082    7.856   1.156
#> 6 FIN01 v.s. FIN03     FIN   q = 2    8.545    7.295   1.171
#>   MF_gamma_cor MF_alpha_cor MF_beta_cor Species_gamma Species_alpha Species_beta
#> 1        9.667        9.662       1.001         3.000         2.000        1.500
#> 2        9.042        8.449       1.069         2.591         1.695        1.529
#> 3        8.556        7.768       1.100         2.330         1.499        1.554
#> 4        9.382        9.182       1.021         3.000         2.000        1.500
#> 5        8.810        7.669       1.147         2.626         1.583        1.659
#> 6        8.313        7.127       1.165         2.374         1.378        1.722

Each row of the output represents the decomposition of species diversity and multi-functionality across two plots. The output contains ID (plotID) which is according to the row names of the input data, Country of two plots, diversity order (Order.q), uncorrelated multi-functionality(MF_gamma, MF_alpha, MF_beta), correlated multi-functionality(MF_gamma_cor, MF_alpha_cor, MF_beta_cor) and decomposition of species diversity(Species_gamma, Species_alpha, Species_beta).

For species_data is not provided, the three columns of decomposition of species diversity are not included in the output.

Graphic Display: ggMF()

The function ggMF(), which extends ggplot2 to the "MF" output object with default arguments, is described as follows:

ggMF <- function(output, by_group = NULL, scale = "fixed", fit = "LMM.interc")
Argument Description
output the output from MF_single or MF_multiple. Note that, the column Species.diversity or the three columns Species_gamma, Species_alpha and Species_beta must be included in it, respectively.
by_group name of the column to be plot in difference colors by group. Default is NULL. For fit is selected to be linear mixed model, you must offer the by_group argument.
scale Are scales shared across all facets (the default, “fixed”), or do they vary across rows (“free_x”), columns (“free_y”), or both rows and columns (“free”)?
fit method of the fitted line. select fit = “lm” for the linear model, or fit = “LMM.interc”, fit = “LMM.slope” and fit = “LMM.both” for the linear mixed model with random effect ‘intercept’, ‘slope’ and ‘both intercept and slope’, respectively.. Default is fit = “LMM.interc”. For each method, estimated of slope are displayed.

The ggMF() function is a wrapper around the ggplot2 package to display the relationship between species diversity and multi-functionality when output is from MF_single, or to display the relationship between the decomposition of species diversity and multi-functionality (MF alpha vs. species alpha, MF beta vs. species beta, and MF gamma vs. species gamma) when output is from MF_multiple using a single line of code. The resulting object is of class "ggplot" or "list" containing two lists of ggplot objects, so it can be manipulated using the ggplot2 tools. Users can visualize the output with different methods of the fitted line by setting the parameter fit:

We first display multi-functionality in single ecosystem with by_group and without by_group.

ggMF(output2, scale = 'fixed', fit = "lm")

output2 <- data.frame("plotID"=rownames(Europe_Forest),
                      "Country"=Europe_Forest$Country) %>% 
  left_join(output2,.,by="plotID")
ggMF(output2, by_group = "Country", scale = 'fixed', fit = "lm")  

And then, display decomposition of multi-functionality in multiple ecosystems with linear model fitted line and linear mixed model with random effect ‘intercept’ fitted line.

figure_lm <- ggMF(output3, by_group = "Country", scale = 'fixed', fit = "lm")
figure_LMM <- ggMF(output3, by_group = "Country", scale = 'fixed', fit = "LMM.interc")
figure_lm$Uncorrelated$ALL

figure_LMM$Uncorrelated$ALL

figure_LMM$Correlated$ALL

figure_LMM$Correlated$Gamma

figure_LMM$Correlated$Alpha

figure_LMM$Correlated$Beta